﻿using System;
using Microsoft.Ajax.Utilities;

namespace DocProcessingWorkflow.Helpers
{
  public class SearchCriteriaHelper
  {
    /// <summary>
    /// Divide the user supplied search criteria into 2 parts
    /// </summary>
    /// <param name="searchCriteria">User supplied search criteria</param>
    /// <returns>Tuple where item1 is search criteria and item2 is documentsearch criteria</returns>
    public static Tuple<string,string> GetSearchCriteria(string searchCriteria)
    {
      if (searchCriteria.Contains(","))
      {
        var searchCriteriaPart = searchCriteria.SubstringUpToFirst(',');
        int index = searchCriteria.IndexOf(',') + 1;
        var documentSearchPart = searchCriteria.Substring(index);
        return new Tuple<string, string>(searchCriteriaPart.Trim(), documentSearchPart.Trim());
      }

      return new Tuple<string, string>(searchCriteria.Trim(), null);
    }
  }
}